<?php

namespace Admin\Controller;

use Common\Controller\BaseController;

/**
 * 后台公共控制器基类
 * 
 * 直接继承项目控制器基类，在该类中不进行登录验证
 * 也不做权限检查
 * 
 * @author: xuhui <xuh86@126.com>
 * @version: $Id$
 * @package: asoc.Admin.Controller
 * 
 */
class PublicController extends BaseController
{

    public function checkLogin()
    {
        $username	=	trim($_POST['username']);
        $password 	=	md5(trim($_POST['password']));

        $status = 0;
        $admin = M('AdminUser');
        $info = $admin->where("`username`='".$username."'")->find();
        if($info != false)
        {
            $status = $info['password'] == $password ? 1 : 2;
        }
        else
        {
            $status = 3;
        }
        if($status == 1)
        {
            session(C('BE_UID'),$info['user_id']);
            $info['last_login_ip'] = get_client_ip();
            $info['last_login_time'] = date('Y-m-d H:i:s');
            $admin->save($info);
        }
        echo $status;
    }


	
	/**
	 * 登陆页面
	 */
	public function login(){
		
		$this->display();
	}

	
	/**
	 *	登出系统
	 */
	public function logout() {
	
		if(session('?'.C('BE_UID'))){
			
			$adminId	=	session(C('BE_UID'));
			
			session(null);
			
			//登录日志
			D('Admin')->addAdminLog('退出',$adminId,'logout');
			
			$this->redirect('Public/login');
			
		}else{
			
			$this->redirect("Public/login","",0.1,"<script>alert('系统已退出！')</script>");
		}
	}
	

}

?>